#include "cpu_monitor_gui.h"
#include "w_regw.h"
/*
 *  cpu_gui/w_iregw.h
 *  
 *              CPU Monitor 
 *
 *    Spring Semester.  044800.    Technion.
 *   Copyright (C) 2006  Evgeny Shulman  and Elizabeth Shtrom 
 */


  RegWin::RegWin( const QString &str,const int &_size, QWidget *parent) :QWidget (parent)
    {
    	
   //titleLabel      = new QLabel(str);
	current =0;
	size = _size;
	regLabel      = new QLabel*[size];
	regValueLabel = new QLabel*[size];
	
	
	QGridLayout *cpuidGridLayout = new QGridLayout();
	
	int column = 0;
	int row =0;
	for ( int i =0; i < size; i++) {
		regLabel [i]     = new QLabel;
		regValueLabel[i] = new QLabel;
		regValueLabel[i]->setFrameStyle(QFrame::Panel | QFrame::Sunken);
		cpuidGridLayout->addWidget(regLabel [i],      row+i, column);
		cpuidGridLayout->addWidget(regValueLabel[i], row+i, column+1);
   }
	
	 QVBoxLayout *regsLayout = new QVBoxLayout;
     regsLayout->addLayout(cpuidGridLayout);
     regsLayout->addStretch(1); 
     
     QGroupBox  *mainGroup   = new QGroupBox(str);
  	 mainGroup->setLayout(regsLayout);
   
    QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(mainGroup);
	setLayout(mainLayout);
}

    
int  RegWin::set_ex_regs ( unsigned long eax,
  	      unsigned long ebx,
  	      unsigned long ecx,
  	      unsigned long edx ){
  	int i =0;
	set_regs(i++, QString ("eAx"), eax);
	set_regs(i++, QString ("eBx"), ebx);	
	set_regs(i++, QString ("eCx"), ecx );
  	set_regs(i++, QString ("eDx"), edx );
  	 return 0;
}


int  RegWin::set_regs (int row, const QString &name,unsigned long value){
  	char str[20];
	sprintf( str, "0x%08lx", value);
	return set_regs ( row, name, str);
}
  
int  RegWin::set_regs (int row, const QString &name,const QString &value){
	if (row >= size ){
		PDEBUG("wrong row in RegWin::set_regs\n");
		return -1;  	
	}
	regLabel[row]       ->setText(name);     	
  	regValueLabel[row]->setText( value); 
  	return 0;

}	
    
 RegWin::~RegWin(){
	//delete[] regLabel;
	//delete[] regValueLabel;
}

